import request from '@/utils/request'

export interface RoleVO {
  id: number
  name: string
  code: string
  sort: number
  status: number
  type: number
  dataScope: number
  dataScopeDeptIds: number[]
  createTime: Date
}

export interface UpdateStatusReqVO {
  id: number
  status: number
}

// 查询角色列表
export const getRolePage = async (params: any) => {
  return request({
    url: '/system/role/page',
    method: 'GET',
    params,
  })
}

// 查询角色（精简)列表
export const getSimpleRoleList = async (): Promise<RoleVO[]> => {
  return request({
    url: '/system/role/simple-list',
    method: 'GET',
  })
}

// 查询角色详情
export const getAddRole = async () => {
  return request({
    url: `/system/role/opt`,
    method: 'GET',
  })
}

// 查询角色详情
export const getRole = async (id: number) => {
  return request({
    url: `/system/role/get?id=${id}`,
    method: 'GET',
  })
}
//保存
export const saveOrUpdate = async (data: RoleVO) => {
  return request({
    url: '/system/role/saveOrUpdate',
    method: 'POST',
    data,
  })
}

// 新增角色
export const createRole = async (data: RoleVO) => {
  return request({
    url: '/system/role/create',
    method: 'POST',
    data,
  })
}

// 修改角色
export const updateRole = async (data: RoleVO) => {
  return request({
    url: '/system/role/update',
    method: 'PUT',
    data,
  })
}

// 修改角色状态
export const updateRoleStatus = async (data: UpdateStatusReqVO) => {
  return request({
    url: '/system/role/update-status',
    method: 'PUT',
    data,
  })
}

// 删除角色
export const deleteRole = async (id: number) => {
  return request({
    url: `/system/role/delete?id=${id}`,
    method: 'PUT',
  })
}
// 批量删除角色
export const deleteRoles = async (id: any) => {
  return request({
    url: `/system/role/deletes?id=${id}`,
    method: 'PUT',
  })
}

// 导出角色
export const exportRole = (params) => {
  return request({
    url: '/system/role/export-excel',
    method: 'GET',
    responseType: 'blob',
    params,
  })
}
